<?php
    $xtpl_list      = new XTemplate("view/news/list.htm");
    
    $heading    = "Thông tin khuyến mại";
    $offset     = $_GET['p'];
    $limit      = 5;
    $offset     = (isset($offset) && ($offset > 0)) ? $offset : 0;
    
    $query  = "SELECT count(*) AS totalRecords FROM news";
    $re     = mysql_query($query);
    $rows   = mysql_fetch_assoc($re);
    $totalRecords   = $rows['totalRecords'];
    
    $pages  = pagging($totalRecords, $offset, $limit, 'index.php?page=news');
    $sql    = "SELECT * FROM news ORDER BY id_n DESC LIMIT " . $offset . ", " . $limit . "";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
        $sqldate    = strtotime($row['date']);
        $date       = date('d-m-Y', $sqldate);
        $content    = cut_string($row['content'],400,1);
        $xtpl_list  -> assign('id', $row['id_n']);
        $xtpl_list  -> assign('title', $row['title']);
        $xtpl_list  -> assign('date', $date);
        $xtpl_list  -> assign('content', $content);
        $xtpl_list  -> insert_loop('LIST.TABLES', array('LIST'=>$row));
    }
    
    $xtpl_list      -> assign('pages', $pages);
    $xtpl_list      -> assign('heading', $heading);
    $xtpl_list      -> parse("LIST");
    $mid            = $xtpl_list -> text("LIST");
?>